package com.htj.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.htj.admin.dao.FoodDao;
import com.htj.admin.domain.Food;
import com.htj.admin.service.FoodServiceInf;
import com.htj.vo.PageListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class FoodServiceImpl implements FoodServiceInf {
    @Autowired
    FoodDao orderDao;

    @Override
    public boolean add(Food Order) {
        boolean bool = false;
        int flag = orderDao.add(Order);
        if(flag == 1){
            bool = true;
        }
        return bool;
    }

    @Override
    public PageListVo<Food> pageList(Map<String, String> map) {
        PageListVo<Food> pageListVo = new PageListVo<>();
        String currentPage = map.get("currentPage");
        String pageSize = map.get("pageSize");
        PageHelper.startPage(Integer.valueOf(currentPage),Integer.valueOf(pageSize));
        List<Food> list = orderDao.pageList(map);
        PageInfo<Food> pageInfo = new PageInfo<>(list);
        List<Food> pageInfoList = pageInfo.getList();
        int total = (int) pageInfo.getTotal();
        pageListVo.setList(pageInfoList);
        pageListVo.setTotal(total);
        return pageListVo;
    }

    @Override
    public boolean update(Food order) {
        boolean bool = false;
        int flag = orderDao.update(order);
        if(flag == 1){
            bool = true;
        }
        return bool;
    }

    @Override
    public boolean delete(Integer id) {
        boolean bool = false;
        int flag = orderDao.delete(id);
        if(flag == 1){
            bool = true;
        }
        return bool;
    }

    @Override
    public boolean changeStatus(Map<String,Integer> map) {
        boolean bool = false;
        int flag = orderDao.changeStatus(map);
        if(flag == 1){
            bool = true;
        }
        return bool;
    }

    @Override
    public List<Food> getAll() {
        List<Food> list = orderDao.getAll();
        return list;
    }

    @Override
    public List<Food> getPie() {
        List<Food> list = orderDao.getPie();
        return list;
    }

    @Override
    public Food getById(String id) {
        Food food = orderDao.getById(id);
        return food;
    }

    @Override
    public boolean changeSaleAndSum(Food food) {
        boolean bool = false;
        int flag = orderDao.changeSaleAndSum(food);
        if(flag == 1){
            bool = true;
        }
        return bool;
    }

    @Override
    public List<Food> searchType(String type) {
        List<Food> list = orderDao.searchType(type);
        return list;
    }

    @Override
    public Food champion() {
        Food food = orderDao.champion();
        return food;
    }

    @Override
    public List<Food> mustPoint() {
        List<Food> foods = orderDao.mustPoint();
        return foods;
    }

    @Override
    public PageListVo<Food> q_pageList(HashMap<String, String> map) {
        PageListVo<Food> pageListVo = new PageListVo<>();
        String currentPage = map.get("currentPage");
        String pageSize = map.get("pageSize");
        PageHelper.startPage(Integer.valueOf(currentPage),Integer.valueOf(pageSize));
        List<Food> list = orderDao.q_pageList(map);
        PageInfo<Food> pageInfo = new PageInfo<>(list);
        List<Food> pageInfoList = pageInfo.getList();
        int total = (int) pageInfo.getTotal();
        pageListVo.setList(pageInfoList);
        pageListVo.setTotal(total);
        return pageListVo;
    }
}
